import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: '数据总览',
        meta: { title: '数据总览', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'Profile', icon: 'user', noCache: true }
      }
    ]
  },
  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Permission',
    meta: {
      title: '任务管理',
      icon: 'edit'
    },
    children: [
      {
        path: 'page',
        component: () => import('@/views/permission/page'),
        name: 'PagePermission',
        meta: {
          title: '任务列表'
        }
      },
      {
        path: 'directive',
        component: () => import('@/views/permission/directive'),
        name: 'DirectivePermission',
        meta: {
          title: '创建任务'
        }
      }
    ]
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/list',
    name: 'Example',
    meta: {
      title: '资源申请',
      icon: 'shopping'
    },
    children: [
      {
        path: 'drag-table',
        component: () => import('@/views/ETL/server-application'),
        name: 'DragTable',
        meta: { title: '服务器申请' }
      },
      {
        path: 'inline-edit-table',
        component: () => import('@/views/ETL/database-application'),
        name: 'InlineEditTable',
        meta: { title: '数据库申请' }
      },
      {
        path: 'complex-table',
        component: () => import('@/views/ETL/form-application'),
        name: 'ComplexTable',
        meta: { title: '数据表申请' }
      }
    ]
  },
  {
    path: '/components',
    component: Layout,
    redirect: 'noRedirect',
    name: 'ComponentDemo',
    meta: {
      title: '监控管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'tinymce',
        component: () => import('@/views/components-demo/tinymce'),
        name: 'TinymceDemo',
        meta: { title: '作业监控' }
      },
      // {
      //   path: 'markdown',
      //   component: () => import('@/views/components-demo/markdown'),
      //   name: 'MarkdownDemo',
      //   meta: { title: '转换监控' }
      // },
      // {
      //   path: 'json-editor',
      //   component: () => import('@/views/components-demo/json-editor'),
      //   name: 'JsonEditorDemo',
      //   meta: { title: '校验作业' }
      // },
      {
        path: 'split-pane',
        component: () => import('@/views/components-demo/split-pane'),
        name: 'SplitpaneDemo',
        meta: { title: '运行日志' }
      },
      // {
      //   path: 'avatar-upload',
      //   component: () => import('@/views/components-demo/avatar-upload'),
      //   name: 'AvatarUploadDemo',
      //   meta: { title: '数据采集日志' }
      // },
      // {
      //   path: 'dropzone',
      //   component: () => import('@/views/components-demo/dropzone'),
      //   name: 'DropzoneDemo',
      //   meta: { title: '数据清洗日志' }
      // },
      // {
      //   path: 'sticky',
      //   component: () => import('@/views/components-demo/sticky'),
      //   name: 'StickyDemo',
      //   meta: { title: '数据对比处理日志' }
      // },
      {
        path: 'count-to',
        component: () => import('@/views/components-demo/count-to'),
        name: 'CountToDemo',
        meta: { title: '服务器监控' }
      }
    ]
  },
  {
    path: '/charts',
    component: Layout,
    redirect: 'noRedirect',
    name: 'Charts',
    meta: {
      title: '系统管理',
      icon: 'documentation'
    },
    children: [
      {
        path: 'mix-chart',
        component: () => import('@/views/charts/mix-chart'),
        name: 'MixChart',
        meta: { title: '员工管理', noCache: true }
      },
      {
        path: 'keyboard',
        component: () => import('@/views/permission/role'),
        name: 'KeyboardChart',
        meta: { title: '角色管理', noCache: true }
      },
      {
        path: 'mixin',
        component: () => import('@/views/components-demo/mixin'),
        name: 'ComponentMixinDemo',
        meta: { title: '部门管理' }
      },
      {
        path: 'back-to-top',
        component: () => import('@/views/components-demo/back-to-top'),
        name: 'BackToTopDemo',
        meta: { title: '审核管理' }
      },
      {
        path: 'drag-dialog',
        component: () => import('@/views/components-demo/drag-dialog'),
        name: 'DragDialogDemo',
        meta: { title: '策略配置' }
      }
    ]
  },
  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1/menu1-1',
    name: 'Nested',
    meta: {
      title: '资产管理',
      icon: 'nested'
    },
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: '服务器管理' },
        redirect: '/nested/menu1/menu1-1'
      },
      {
        path: 'menu2',
        name: 'Menu2',
        component: () => import('@/views/nested/menu2/index'),
        meta: { title: '数据库管理' }
      },
      {
        path: 'drag-kanban',
        component: () => import('@/views/ETL/form-application'),
        name: 'DragKanbanDemo',
        meta: { title: '数据表管理' }
      }
    ]
  },
  {
    path: '/table',
    component: Layout,
    redirect: '/table/complex-table',
    name: 'Table',
    meta: {
      title: '个人中心',
      icon: 'user'
    },
    children: [
      {
        path: 'dynamic-table',
        component: () => import('@/views/table/dynamic-table/index'),
        name: 'DynamicTable',
        meta: { title: '修改个人资料' }
      },
      {
        path: 'create',
        component: () => import('@/views/example/create'),
        name: 'CreateArticle',
        meta: { title: '我的服务器' }
      },
      {
        path: 'create1',
        component: () => import('@/views/example/edit'),
        name: 'EditArticle',
        meta: { title: '我的数据库' }
      },
      {
        path: 'list',
        component: () => import('@/views/example/list'),
        name: 'ArticleList',
        meta: { title: '我的数据表' }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  /** when your routing map is too long, you can split it into small modules **/
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
